package com.tskj.leonsu.controller;

import com.alibaba.fastjson.JSONObject;
import com.tskj.leonsu.service.LoginService;
import com.tskj.leonsu.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author LeonSu
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private LoginService loginService;

    @PostMapping("/save")
    @ResponseBody
    public JSONObject saveCheckResult(@RequestParam String token, @RequestBody JSONObject data) {
        String adUserName = loginService.getAdUserName(token);
        if (adUserName == null || adUserName.isEmpty()) {
            JSONObject ret = new JSONObject();
            ret.put("code", 1);
            ret.put("errMsg", "未找到对应的信息，无法保存");
            return ret;
        }
        return studentService.saveCheckStatus(adUserName, data);
    }
}
